package com.zhl.study.configuration;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.zhl.study.enums.SystemConst;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @description 元数据存储入库
 * @Author: z156940l@outlook.com
 * @className MyMetaObjectHandler
 * @Date: 2023/4/17 22:14
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("createTime", LocalDateTime.now(), metaObject);
        this.setFieldValByName("updateTime", LocalDateTime.now(), metaObject);
        this.setFieldValByName("status", SystemConst.NOT_DELETE.getCode(), metaObject);
        //TODO 用户有记录后期再做
//        UserRespVO userRespVO = WebLogAcpect.getUser();
//        if (Objects.nonNull(userRespVO)) {
//            this.setFieldValByName("createUser", userRespVO.getId(), metaObject);
//        }
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        //TODO 用户有记录后期再做
//        UserRespVO userRespVO = WebLogAcpect.getUser();
//        if (Objects.nonNull(userRespVO)) {
//            this.setFieldValByName("updateUser", userRespVO.getId(), metaObject);
//        }
        this.setFieldValByName("updateTime", LocalDateTime.now(), metaObject);

    }
}